package crew.gwt.client.widgets;

import com.google.gwt.dom.client.Document;
import com.google.gwt.event.logical.shared.CloseEvent;
import com.google.gwt.event.logical.shared.CloseHandler;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

public class MessagePopupPanel extends PopupPanel implements CloseHandler<PopupPanel>
{
	private static int COUNT_SHOWING = 0;
	
	public MessagePopupPanel(Boolean isSuccess,final String... messages)
	{
		super(true,false);
		addCloseHandler(this);
		setAnimationEnabled(true);
		setSize("250px", "150px");
		final int width = Document.get().getClientWidth();
		final int height = Document.get().getClientHeight()+Document.get().getScrollTop();
		setPopupPosition(width-270, height-(170*(COUNT_SHOWING+1)));
		
		VerticalPanel vp = new VerticalPanel();
		if(isSuccess!=null){
			if(isSuccess) vp.addStyleName("popupContentSuccess");
			else vp.addStyleName("popupContentFailed");
		}
		for(String message : messages){
			vp.add(new ClassicLabel(message));
		}
		setWidget(vp);
		COUNT_SHOWING++;
	}

	@Override
	public void onClose(CloseEvent<PopupPanel> arg0) {
		if( COUNT_SHOWING > 0 )
			COUNT_SHOWING--;
	}
}
